//
//  RBKHtmlStringVC.m
//  RuiBeiKang
//
//  Created by 江伟 on 2018/12/22.
//  Copyright © 2018年 JW. All rights reserved.
//

#import "RBKHtmlStringVC.h"

@interface RBKHtmlStringVC ()
@property (nonatomic,strong) UIWebView *webView;
@property (nonatomic,strong) UIView *bottomView;
@end

@implementation RBKHtmlStringVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Do any additional setup after loading the view.
}

- (void)setupViews {
    [self.view addSubview:self.webView];
}

- (void)loadData {
    if (_urlString) {
   
        [NetWork POSTWithUrlString:kInterfaceAllUrl(_urlString) parmas:_parma ? :@{} successBloock:^(id responseObject) {
            self.title = responseObject[@"title"];
            NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@",NSTemporaryDirectory()]];
            NSMutableString *str = [NSMutableString string];
            NSString *w = [NSString stringWithFormat:@"<head><style>img{width:%fpx !important;}</style></head>",KWidth - 20];
            [str appendString:w];
            [str appendString:responseObject[@"content"]];
            [self.webView loadHTMLString:str baseURL:url];
        } failureBlock:^(NSError *error) {
            
        }];
    }
}

- (void)bottomViewBtn1Text:(NSString *)text1 color1:(UIColor *)color1 btn2Text:(NSString *)text2 color2:(UIColor *)color2 {
    if (!STR_Is_NullOrEmpty(text2)) { // 有值
        self.bottomViewBtn2.hidden = NO;
        self.bottomViewBtn1.frame = CGRectMake(0, 0, KWidth/2.0, aufont(50));
        self.bottomViewBtn2.frame = CGRectMake(KWidth/2.0, 0, KWidth/2.0, aufont(50));
        [self.bottomViewBtn2 setTitle:text2 forState:UIControlStateNormal];
        if (color2 != nil) {
            self.bottomViewBtn2.backgroundColor = color2;
        }
    }
    if (color1 != nil) {
        self.bottomViewBtn1.backgroundColor = color1;
    }
    [self.bottomViewBtn1 setTitle:text1 forState:UIControlStateNormal];
    [self.view addSubview:self.bottomView];
    [self.bottomView addSubview:self.bottomViewBtn1];
    [self.bottomView addSubview:self.bottomViewBtn2];
    self.webView.frame = CGRectMake(0, 0, KWidth, ViewHeight3 - aufont(50));
}

- (UIWebView *)webView {
    if (!_webView) {
        _webView = [UIWebView new];
        _webView.backgroundColor = [UIColor whiteColor];
        _webView.frame = self.view.bounds;
    }
    return _webView;
}

- (UIView *)bottomView {
    if (!_bottomView) {
        _bottomView = [UIView new];
        _bottomView.frame = CGRectMake(0, ViewHeight3 - aufont(50), KWidth, aufont(50));
    }
    return _bottomView;
}

- (UIButton *)bottomViewBtn1 {
    if (!_bottomViewBtn1) {
        _bottomViewBtn1 = [UIButton setupBtnWithBackgroundColor:mainColor title:@"" titleColor:[UIColor whiteColor] isBkImg:NO image:nil target:self selector:@selector(clickBottomViewBtn1:)];
        _bottomViewBtn1.frame = CGRectMake(0, 0, KWidth, aufont(50));
    }
    return _bottomViewBtn1;
}

- (UIButton *)bottomViewBtn2 {
    if (!_bottomViewBtn2) {
        _bottomViewBtn2 = [UIButton setupBtnWithBackgroundColor:mainColor title:@"" titleColor:[UIColor whiteColor] isBkImg:NO image:nil target:self selector:@selector(clickBottomViewBtn2:)];
        _bottomViewBtn2.hidden = YES;
    }
    return _bottomViewBtn2;
}

- (void)clickBottomViewBtn1:(UIButton *)btn1 {
//    [NetWork POSTWithUrlString:kInterfaceAllUrl(PATH_ArticleNews_collect) parmas:@{@"article_id":} successBloock:^(id responseObject) {
//        
//    } failureBlock:^(NSError *error) {
//        
//    }];
}

- (void)clickBottomViewBtn2:(UIButton *)btn2 {
    
}

@end
